home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QuickTime - The Beta Release
/
QuickTime - The Beta Release.iso
/
Programming Stuff
/
Sample Code
/
BareBones
/
Bare Bones.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-05
|
3KB
|
115 lines
/**************************************************
*
* Bare Bones Player
* This program demonstrates how to open a movie file
* and play it in a window
*
* Rich Williams 12/90
* Updated 2/91, 3/91
* Updated to 4.04 interfaces 4/91
* Updated to MPW/Think 5.0/DSG interfaces 9/91 Chris Thorman
*
***************************************************/
#include "Movies.h"
#include <Memory.h>
#include <Fonts.h>
#include <OSEvents.h>
#include <Menus.h>
/**************************************************
* Variables
***************************************************/
Movie theMovie; /* Info about the movie returned by OpenMovie*/
Rect dispBounds;
WindowPtr movieWindow; /* Window to play the movie in */
OSErr theErr;
/* Stuff for opening the file */
FSSpec mySpec; /* File System record for the file */
short resRefNum; /* Resource reference number when opening the file */
Point dlgPos = {100,100}; /* Position the dialog box */
Str255 prompt = "\pSelect movie file to play:";
short numtypes = 1;
SFTypeList types={'MooV'};
SFReply sfr;
void PlayTheMovie(void);
/**************************************************
*
* main()
* This is where everything happens
*
***************************************************/
main()
{
MaxApplZone(); /* Initialize the managers */
InitGraf(&qd.thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
InitCursor();
if(theErr = EnterMovies()) /* Start up the movie tools */
return; /* Bail out if error. A nice person would put an alert up */
PlayTheMovie(); /* Do it */
}
/**************************************************
*
* PlayTheMovie() Opens and plays Movie File
*
***************************************************/
void
PlayTheMovie(void)
{
/* Find out which movie file to play */
SFGetFile( dlgPos, prompt,nil,numtypes,types,nil,&sfr );
if (!sfr.good) return; /* Return if no selection */
/* Now make an FSSpec record of the info */
theErr = FSMakeFSSpec(sfr.vRefNum,0,sfr.fName,&mySpec);
/* First open the movie file */
if (theErr = OpenMovieFile(&mySpec, &resRefNum, 0))
return; /* Bail out if it didn't work */
if (theErr = NewMovieFromFile( &theMovie,resRefNum, nil, nil,0, nil ))
return; /* Bail out if it didn't work */
/* Get the bounds for the movie and make sure the top left is 0,0 */
/* so the movie won't be offset within the window */
GetMovieBox( theMovie, &dispBounds);
OffsetRect(&dispBounds,-dispBounds.left,-dispBounds.top);
SetMovieBox(theMovie, &dispBounds);
/* Set up the window for the movie to play in */
OffsetRect(&dispBounds,100,100); /* Make sure window not under menu bar */
movieWindow = NewCWindow(0L,&dispBounds,(StringPtr)sfr.fName,true,0,(WindowPtr)-1L,false,0L); /* Make a new window */
SetPort(movieWindow);
SetMovieGWorld(theMovie,nil,nil); /* Play the movie in the window */
/* Now we're ready to play the movie */
GotoBeginningOfMovie(theMovie);
PrerollMovie(theMovie,0,0); /* Get the movie ready to play */
SetMovieActive(theMovie,true);
StartMovie(theMovie); /* Start the movie */
/* Play the movie until done or the mouse button has been pressed */
while ( !IsMovieDone(theMovie) && !Button() )
MoviesTask(theMovie,0);
/* Clean up and go home */
DisposeMovie(theMovie); /* Get rid of the movie */
CloseMovieFile(resRefNum);
}